<?php
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;

?>
<style>
    .table th:first-child{width: 27.37%;}
    .table th:nth-child(2){width: 54.68%;}
</style>
<div class="row">
    <div class="container lh30">
        <a class="topNav" href="<?=Url::toRoute('/system/site/index')?>" style=""><img src="<?=Yii::getAlias('@web/backend/img/home/home.png');?>" alt="首页"/>返回首页</a>
    </div>
</div>
 <div class="row nav-brand-bg">
     <div class="container">
        <ul id="myTab" class="nav nav-tabs">
            <li class="active"><a href="<?=Url::toRoute(['config/list','type'=>1]) ?>" >充值卡</a></li>
            <li><a href="<?=Url::toRoute(['config/list','type'=>2]) ?>" >疗程卡</a></li>
            <li><a href="<?=Url::toRoute(['config/list','type'=>3]) ?>" >合作项目</a></li>
            <li><a href="<?=Url::toRoute(['config/list','type'=>4]) ?>" >服务项目</a></li>
            <li><a href="<?=Url::toRoute(['config/list','type'=>5]) ?>" >房间</a></li>
            <li><a href="<?=Url::toRoute(['config/list','type'=>6]) ?>" >库存</a></li>
        </ul>
     </div>
</div>
<div  class="container">
     <a href="javascript:;" class="add-recharge btnBg mg20-y"><i class="fa fa-plus-circle" style="margin-right: 50px;font-size: 20px;vertical-align: middle;"></i>添加</a>
    <div class="table-responsive">
        <?php if(empty($list)){?>
        <table class="table table-bordered">
            <thead>
            <tr>
                <th >名称</th>
                <th>零售价</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr class="lastTr" style="display: none;">
                <form id="test" method="post" role="form" action="<?=Url::toRoute('config/add')?>">
                    <td><input class="read" id="key1" name="key" type="text"/></td>
                    <td><input class="read" id="val1"  name="val" type="text"/><input type="hidden" name="type" value="1" /></td>
                    <td><input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
                        <input type="submit" value="保存" onclick="return checkAddConfig()"  class="edit btn btn-sm btn-borB4"   />
                        <a href="#" class="edit restb btn btn-sm btn-borB4 ml20" >取消</a></td>
                </form>
            </tr>
            <tr class="lastSet">
                <td colspan="3" align="center"><img src="<?=Yii::getAlias('@web/backend/img/nodata.gif');?>"></td>
            </tr>
            </tbody>
        </table>
        <?php }else{?>
        <table class="table table-bordered" style="table-layout: fixed;">
            <thead>
                <tr>
                    <th >名称</th>
                    <th>零售价</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>

                <?php foreach ($list as $r){?>
                    <tr>
                        <?php ActiveForm::begin(['action'=>Url::toRoute('config/update')])?>
                        <td><input class="read-only cas" type="text" name="key" value="<?=Html::encode($r['config_key']) ?>" readonly/></td>
                        <td><input class="read-only val" type="text" name="val" value="<?=Html::encode($r['config_val']) ?>" readonly/><input type='hidden' name='id' value='<?=Html::encode($r['config_id']) ?>'></td>
                        <td>
                            <input type="hidden" name="type" value="1" />
                            <a href="#" class="editBtn btn btn-sm btn-borB4">编辑</a>
                            <div class="fadeBox" style="display: none">
                                <input  type="submit" class="edit btn btn-sm btn-borB4 cet"  value="保存" />
                                <a href="#" class="edit rest btn btn-sm btn-borB4 ml20">取消</a>
                            </div>
                        </td>
                        <?php ActiveForm::end();?>
                    </tr>
                <?php }?>

            <tr class="lastTr" style="display: none;">
                <form id="test" method="post" role="form" action="<?=Url::toRoute('config/add')?>">
                    <td><input class="read" id="key1" value="" name="key" type="text"/></td>
                    <td><input class="read " id="val1"  name="val" value="" type="text"/><input type="hidden" name="type" value="1" /></td>
                    <td><input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
                    <input type="submit" value="保存" onclick="return checkAddConfig()"  class="edit btn btn-sm btn-borB4"   />
                    <a href="#" class="edit restb btn btn-sm btn-borB4 ml20" >取消</a></td>
                </form>
            </tr>
            </tbody></table>
        <?php }?>
        <div class="page">
        <?=LinkPager::widget([
            'pagination' => $page,
            'firstPageLabel' => '首页',
            'nextPageLabel' => '下一页',
            'prevPageLabel' => '上一页',
            'lastPageLabel' => '末页',
            'hideOnSinglePage'=>true
        ]); ?>
        </div>
    </div>
</div>

<?php $this->beginBlock('js_index_end') ?>
    $(function(){
        $('.table tr').dblclick(function(){
            var $this = $(this);
            $(this).addClass('current');
            $(this).siblings().removeClass('current');
            $this.find('input[type="text"]').removeClass('read-only').removeAttr('readonly');
            $this.find('.fadeBox').show();
            $this.find('.editBtn').hide()
        })
        $('.rest').click(function(){
            $(this).parent().parent().parent().removeClass('current');
            $(this).parent().hide();
            $(this).parent().parent().find('.editBtn').show();
            $(this).parent().parent().parent().find('input[type="text"]').addClass('read-only').attr('readonly',true);
        })
    $('.editBtn').click(function(){
        $(this).hide();
        $(this).next().show();
        $(this).parent().parent().addClass('current');
        $(this).parent().parent().siblings().removeClass('current');
        $(this).parent().parent().find('input[type="text"]').removeClass('read-only').removeAttr('readonly');
    })
    $('.add-recharge').click(function(e){
        $('.lastTr').addClass('current');
        $('.lastTr').show();
        $('.lastSet').hide();
    })
    $('.restb').click(function(){
        $('.lastTr').hide();
        $('.lastSet').show();
    })
})
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['js_index_end'], $this::POS_END); ?>
<?php $this->registerJsFile("@web/system/config/config.js", ['position' => $this::POS_END]); ?>
